﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace DataAccess
{
    /// <summary>
    /// 数据访问类:TB_YGYXRK_HD
    /// </summary>
    public partial class TB_YGYXRK_HD
    {
        public TB_YGYXRK_HD()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(decimal NID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TB_YGYXRK_HD");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Add(Model.TB_YGYXRK_HD model)
        {
            model.NID = CommonExecute.GetID(model.GetType().Name);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TB_YGYXRK_HD(");
            strSql.Append("NID,NRWID,NYPTS,NYPXH,CSN,FSJL,NSMPS,FSLRGB,CFW,NCFGH,NCFCH,NCFLH,NJZBH)");
            strSql.Append(" values (");
            strSql.Append(":NID,:NRWID,:NYPTS,:NYPXH,:CSN,:FSJL,:NSMPS,:FSLRGB,:CFW,:NCFGH,:NCFCH,:NCFLH,:NJZBH)");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,10),
					new OracleParameter(":NRWID", OracleType.Number,10),
					new OracleParameter(":NYPTS", OracleType.Number,1),
					new OracleParameter(":NYPXH", OracleType.NVarChar),
					new OracleParameter(":CSN", OracleType.NVarChar),
					new OracleParameter(":FSJL", OracleType.Number,10),
					new OracleParameter(":NSMPS", OracleType.Number,10),
					new OracleParameter(":FSLRGB", OracleType.Number,10),
					new OracleParameter(":CFW", OracleType.VarChar,1500),
					new OracleParameter(":NCFGH", OracleType.Number,10),
					new OracleParameter(":NCFCH", OracleType.Number,10),
					new OracleParameter(":NCFLH", OracleType.Number,10),
					new OracleParameter(":NJZBH", OracleType.NVarChar)};
            parameters[0].Value = model.NID;
            parameters[1].Value = model.NRWID;
            parameters[2].Value = model.NYPTS;
            parameters[3].Value = model.NYPXH;
            parameters[4].Value = model.CSN;
            parameters[5].Value = model.FSJL;
            parameters[6].Value = model.NSMPS;
            parameters[7].Value = model.FSLRGB;
            parameters[8].Value = model.CFW;
            parameters[9].Value = model.NCFGH;
            parameters[10].Value = model.NCFCH;
            parameters[11].Value = model.NCFLH;
            parameters[12].Value = model.NJZBH;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.TB_YGYXRK_HD model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update TB_YGYXRK_HD set ");
            strSql.Append("NRWID=:NRWID,");
            strSql.Append("NYPTS=:NYPTS,");
            strSql.Append("NYPXH=:NYPXH,");
            strSql.Append("CSN=:CSN,");
            strSql.Append("FSJL=:FSJL,");
            strSql.Append("NSMPS=:NSMPS,");
            strSql.Append("FSLRGB=:FSLRGB,");
            strSql.Append("CFW=:CFW,");
            strSql.Append("NCFGH=:NCFGH,");
            strSql.Append("NCFCH=:NCFCH,");
            strSql.Append("NCFLH=:NCFLH,");
            strSql.Append("NJZBH=:NJZBH");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NRWID", OracleType.Number,10),
					new OracleParameter(":NYPTS", OracleType.Number,1),
					new OracleParameter(":NYPXH", OracleType.NVarChar),
					new OracleParameter(":CSN", OracleType.NVarChar),
					new OracleParameter(":FSJL", OracleType.Number,10),
					new OracleParameter(":NSMPS", OracleType.Number,10),
					new OracleParameter(":FSLRGB", OracleType.Number,10),
					new OracleParameter(":CFW", OracleType.VarChar,1500),
					new OracleParameter(":NCFGH", OracleType.Number,10),
					new OracleParameter(":NCFCH", OracleType.Number,10),
					new OracleParameter(":NCFLH", OracleType.Number,10),
					new OracleParameter(":NJZBH", OracleType.NVarChar),
					new OracleParameter(":NID", OracleType.Number,10)};
            parameters[0].Value = model.NRWID;
            parameters[1].Value = model.NYPTS;
            parameters[2].Value = model.NYPXH;
            parameters[3].Value = model.CSN;
            parameters[4].Value = model.FSJL;
            parameters[5].Value = model.NSMPS;
            parameters[6].Value = model.FSLRGB;
            parameters[7].Value = model.CFW;
            parameters[8].Value = model.NCFGH;
            parameters[9].Value = model.NCFCH;
            parameters[10].Value = model.NCFLH;
            parameters[11].Value = model.NJZBH;
            parameters[12].Value = model.NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_YGYXRK_HD ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public static bool DeleteList(string where)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_YGYXRK_HD ");
            if (!string.IsNullOrEmpty(where))
            {
                strSql.Append(" where " + where);
                int rows = DbHelperOra.ExecuteSql(strSql.ToString());
                if (rows > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.TB_YGYXRK_HD GetModel(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,NRWID,NYPTS,NYPXH,CSN,FSJL,NSMPS,FSLRGB,CFW,NCFGH,NCFCH,NCFLH,NJZBH from TB_YGYXRK_HD ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            Model.TB_YGYXRK_HD model = new Model.TB_YGYXRK_HD();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NRWID"] != null && ds.Tables[0].Rows[0]["NRWID"].ToString() != "")
                {
                    model.NRWID = decimal.Parse(ds.Tables[0].Rows[0]["NRWID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPTS"] != null && ds.Tables[0].Rows[0]["NYPTS"].ToString() != "")
                {
                    model.NYPTS = decimal.Parse(ds.Tables[0].Rows[0]["NYPTS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPXH"] != null && ds.Tables[0].Rows[0]["NYPXH"].ToString() != "")
                {
                    model.NYPXH = ds.Tables[0].Rows[0]["NYPXH"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CSN"] != null && ds.Tables[0].Rows[0]["CSN"].ToString() != "")
                {
                    model.CSN = ds.Tables[0].Rows[0]["CSN"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FSJL"] != null && ds.Tables[0].Rows[0]["FSJL"].ToString() != "")
                {
                    model.FSJL = decimal.Parse(ds.Tables[0].Rows[0]["FSJL"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NSMPS"] != null && ds.Tables[0].Rows[0]["NSMPS"].ToString() != "")
                {
                    model.NSMPS = decimal.Parse(ds.Tables[0].Rows[0]["NSMPS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FSLRGB"] != null && ds.Tables[0].Rows[0]["FSLRGB"].ToString() != "")
                {
                    model.FSLRGB = decimal.Parse(ds.Tables[0].Rows[0]["FSLRGB"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CFW"] != null && ds.Tables[0].Rows[0]["CFW"].ToString() != "")
                {
                    model.CFW = ds.Tables[0].Rows[0]["CFW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NCFGH"] != null && ds.Tables[0].Rows[0]["NCFGH"].ToString() != "")
                {
                    model.NCFGH = decimal.Parse(ds.Tables[0].Rows[0]["NCFGH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NCFCH"] != null && ds.Tables[0].Rows[0]["NCFCH"].ToString() != "")
                {
                    model.NCFCH = decimal.Parse(ds.Tables[0].Rows[0]["NCFCH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NCFLH"] != null && ds.Tables[0].Rows[0]["NCFLH"].ToString() != "")
                {
                    model.NCFLH = decimal.Parse(ds.Tables[0].Rows[0]["NCFLH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NJZBH"] != null && ds.Tables[0].Rows[0]["NJZBH"].ToString() != "")
                {
                    model.NJZBH = ds.Tables[0].Rows[0]["NJZBH"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,NRWID,NYPTS,NYPXH,CSN,FSJL,NSMPS,FSLRGB,CFW,NCFGH,NCFCH,NCFLH,NJZBH ");
            strSql.Append(" FROM TB_YGYXRK_HD ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        public static DataSet GetListFromView(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM V_YGYXRK_BASE_HD ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "TB_YGYXRK_HD";
            parameters[1].Value = "NID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

